﻿using System;
using System.Windows;
using System.Windows.Controls;

namespace DesktopInfo
{
    /// <summary>
    /// Interaction logic for Clock.xaml
    /// </summary>
    public partial class Clock : UserControl
    {
        public Clock()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(Clock_Loaded);
        }

        void Clock_Loaded(object sender, RoutedEventArgs e)
        {
            System.Timers.Timer refreshTimer = new System.Timers.Timer(1000);
            refreshTimer.Elapsed += (source, evntArgs) =>
            {

                this.InvokeIfRequired((value) => seconds.Content = value, DateTime.Now.Second.ToString("00"));
                this.InvokeIfRequired((value) => minutes.Content = value, DateTime.Now.Minute.ToString("00"));
                this.InvokeIfRequired((value) => hours.Content = value, DateTime.Now.Hour.ToString("00"));
                this.InvokeIfRequired((value) => date.Content = value, DateTime.Now.ToString("dddd, dd MM yyyy"));
            };
            refreshTimer.Enabled = true;
            refreshTimer.Start();
        }
    }
}
